package function

import (
	"fmt"
	"math/rand"
	"time"
)

type IpFunction struct {
	size  int
	clazz string // 支持A B C 三类IP地址
	data  []interface{}
}

func DefaultIp(size int, clazz string) *IpFunction {
	return &IpFunction{
		size:  size,
		clazz: clazz,
		data:  make([]interface{}, 0, size),
	}
}

func (ip *IpFunction) Build() []interface{} {
	rand.Seed(time.Now().Unix())
	for i := 0; i < ip.size; i++ {
		var temp string
		if ip.clazz == "A" {
			// A 类 ip地址    10.0.0.0 ~ 10.255.255.255
			temp = fmt.Sprintf("10.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255))
		} else if ip.clazz == "B" {
			// B 类 ip地址    172.16.0.0 ~ 172.31.255.255
			temp = fmt.Sprintf("172.%d.%d.%d", rand.Intn(15)+16, rand.Intn(255), rand.Intn(255))
		} else {
			// C 类 ip地址    192.168.0.0 ~ 192.168.255.255
			temp = fmt.Sprintf("192.168.%d.%d", rand.Intn(255), rand.Intn(255))
		}
		ip.data = append(ip.data, temp)
	}
	return ip.data
}
